import * as service from "@/service";
import { ICate } from "./interface";
import _ from "lodash";
const cate: ICate = {
  namespaced: true,
  state: {
    cates: [],
  },
  actions: {
    async getCate({ commit }) {
      const result = await service.getCateList();
      const action = {
        type: "GET_CATE",
        payload: result?.data?.data,
      };
      commit(action);
    },
  },
  mutations: {
    GET_CATE(state, action) {
      state.cates = action.payload.map((item: any) => {
        item.text = item.name;
        return _.omit(item, ["name"]);
      });
    },
  },
};
export default cate;
